var loginapp = angular.module("loginModule", [ "httpPost" ]);
loginapp.controller("loginController", function($scope, $http) {
	var vm = $scope.vm = {
		user : {},
		verifycode : '',
		error : false,
		resutl : 0,
	}

	vm.verifyImg = "kaptcha.do";
	vm.refrashImg = function() {
		vm.verifyImg = "kaptcha.do?" + Math.floor(Math.random() * 100);
	};

	vm.login = function(form) {
		vm.user.$showError = true;
		form.$setDirty();
		if (form.$valid) {
			var url = "login.do";
			$http.post(url, {
				username : vm.user.username,
				password : vm.user.password,
				captcha : vm.user.captcha
			}).success(function(data) {
				if (data.result == 0) {
					window.location = "admin/index.jsp";
				} else {
					vm.user.$showMessage = true;
					vm.user.$message = data.message;
					vm.refrashImg();
				}
			})
		}
	}

});